######################################set linux compile env #############################
######################################set linux compile env #############################
ifeq ($(strip $(targetbase)),linux)
ifeq ($(strip $(LINUX_LK)),TRUE)
include $(SDK_DIR)/mk/sys_km.mk
#dkits
SDK_DKITS_SRCS = $(shell find $(SDK_DIR)/dkits/ctc_dkit_cli.c)
SDK_DKITS_SRCS += $(shell find $(SDK_DIR)/dkits/ctc_dkit_api.c)
SDK_DKITS_SRCS += $(shell find $(SDK_DIR)/dkits/ctc_dkit_dump_cfg.c)
ifeq ($(USW),yes)
SDK_DKITS_SRCS += $(shell find $(SDK_DIR)/dkits/common -maxdepth 1 -name "*.c")
SDK_DKITS_SRCS += $(foreach n, $(chipname), $(shell find $(SDK_DIR)/dkits/common/$(n) -name "*.c"))
endif
SDK_DKITS_SRCS += $(foreach n, $(COMPATIBAL_CHIP), $(shell find $(SDK_DIR)/dkits/$(n) -name "*.c"))
SDK_DKITS_OBJS = $(patsubst %.c,%.o,$(SDK_DKITS_SRCS))
SDK_DKITS_OBJS := $(subst $(SDK_DIR)/dkits/,,$(SDK_DKITS_OBJS))

lib-m += $(SDK_DKITS_OBJS)
else
include $(MK_DIR)/sys.mk
OBJ_DIR=$(OBJ_BASE_DIR)/dkits
__LIB_DIR := $(LIB_DIR)

PROG = dkcli

SRCS = ctc_dkit_main.c

CPPFLAGS += -I$(SDK_DIR)/dal/include
CPPFLAGS += -I$(SDK_DIR)/sal/include
CPPFLAGS += -I$(SDK_DIR)/driver
CPPFLAGS += -I$(SDK_DIR)/driver/api/
CPPFLAGS += -I$(SDK_DIR)/libctccli/include
CPPFLAGS += -I$(SDK_DIR)/dkits/common
CPPFLAGS += -I$(SDK_DIR)/core/common/include

ifeq ($(strip $(ARCH)),um)
CPPFLAGS += $(foreach n, $(chipname), -I$(SDK_DIR)/mem_model/$(n)/include)
LIBMEMMODEL = $(LIB_DIR)/libmemmodel.a
endif

LIBSAL    = $(LIB_DIR)/libsal.a
LIBDAL    = $(LIB_DIR)/libdal.a
LIBDRV    = $(LIB_DIR)/libdrv.a
LIBLIBCTCCLI  = $(LIB_DIR)/liblibctccli.a

DKITCLI = $(LIB_DIR)/libdkit.a


ifeq ($(strip $(ARCH)),um)
DEP_LIBS = $(LIBLIBCTCCLI) $(LIBDRV) $(LIBSAL) $(LIBDAL) $(LIBMEMMODEL) $(DKITCLI)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -ldkit -llibctccli -ldrv -ldal -lmemmodel -lsal -lpthread -lm
else
DEP_LIBS = $(LIBLIBCTCCLI) $(LIBDRV) $(LIBSAL) $(LIBDAL) $(DKITCLI)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -ldkit -llibctccli -ldrv -ldal -lsal -lpthread -lm
endif


include $(MK_DIR)/prog.mk
endif
endif

############################# vxworks #####################################
ifeq ($(strip $(targetbase)),vxworks)
include $(MK_DIR)/sys_vx.mk

__LIB_DIR := $(LIB_DIR)

PROG = dkcli

SRCS = ctc_dkit_main.c

CPPFLAGS += -I$(SDK_DIR)/dal/include
CPPFLAGS += -I$(SDK_DIR)/sal/include
CPPFLAGS += -I$(SDK_DIR)/driver
CPPFLAGS += -I$(SDK_DIR)/driver/api/
CPPFLAGS += -I$(SDK_DIR)/libctccli/include
CPPFLAGS += -I$(SDK_DIR)/dkits/common
CPPFLAGS += -I$(SDK_DIR)/core/common/include

ifeq ($(strip $(ARCH)),um)
CPPFLAGS += $(foreach n, $(chipname), -I$(SDK_DIR)/mem_model/$(n)/include)
LIBMEMMODEL = $(LIB_DIR)/libmemmodel.a
endif

LIBSAL    = $(LIB_DIR)/libsal.a
LIBDAL    = $(LIB_DIR)/libdal.a
LIBDRV    = $(LIB_DIR)/libdrv.a
LIBLIBCTCCLI  = $(LIB_DIR)/liblibctccli.a

DKITCLI = $(LIB_DIR)/libdkit.a


ifeq ($(strip $(BOARD)),vxworks-sim)
DEP_LIBS = $(LIBLIBCTCCLI) $(LIBDRV) $(LIBSAL) $(LIBDAL) $(LIBMEMMODEL) $(DKITCLI)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -ldkit -llibctccli -ldrv -ldal -lmemmodel -lsal
else
DEP_LIBS = $(LIBLIBCTCCLI) $(LIBDRV) $(LIBSAL) $(LIBDAL) $(DKITCLI)
LD_LIBS = -L$(__LIB_DIR) -L$(LIB_DIR) -ldkit -llibctccli -ldrv -ldal -lsal
endif

OBJS = $(wildcard $(OBJ_DIR)/*.o) $(foreach n, $(chipname), $(wildcard $(OBJ_DIR)/$(n)/*.o))
DEPS = $(wildcard $(OBJ_DIR)/*.d) $(foreach n, $(chipname), $(wildcard $(OBJ_DIR)/$(n)/*.d))

$(BIN_DIR)/$(PROG): $(OBJS) $(DEP_LIBS)
	$(shell mkdir -p $(dir $@))
	@echo "LD  => $(subst $(BLD_DIR),build.$(CPU).$(VER),$@)" && \
	$(CC) $(LD_FLAGS) -o $@ $(OBJS) $(LD_LIBS)

.PHONY: clean
clean:
	rm -rf $(BIN_DIR)/$(PROG)

endif
